# Use C-a instead of C-b as the prefix
set -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

# allow terminal scrolling
set-option -g terminal-overrides 'urxvt*:smcup@:rmcup@'

# set 256 colors
set-option -g default-terminal "screen-256color"

set-option -g display-time 2000

# be more responsive, changing the default delay
set-option -sg escape-time 1

# set scrollback
set-option -g history-limit 10000

# Start numbering at 1
set-option -g base-index 1
set-window-option -g pane-base-index 1

# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf  \; display "Reloaded!"

## Copy mode

# Copy selection to clipboard
unbind-key -T copy-mode M-w
bind-key -T copy-mode M-w send -X copy-pipe-and-cancel "xsel -ib"

#Make Home & End keys work in copy mode
bind-key -T copy-mode Home send -X start-of-line
bind-key -T copy-mode End send -X end-of-line

# Paste from clipboard
unbind-key M-y
bind-key -n M-y run "tmux set-buffer \"$(xsel -ob)\"; tmux paste-buffer"

# Home/End keys
bind -n Home send-keys C-a
bind -n End send-keys C-e

# Terminal title
set-option -g set-titles on
set-option -g set-titles-string '[#S:#I] #W'
set-window-option -g automatic-rename on

# aggresive resize
set-window-option -g aggressive-resize on

# Saner splitting.
bind v split-window -h
bind h split-window -v
bind S choose-session

# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5

# Mode
set-option -g mode-style bg=brightblack

#Status bar
set-option -g status off
set-hook -g window-linked "if-shell -F '#{!=:#{session_windows},1}' 'set status on'"
set-hook -g window-unlinked "if-shell -F '#{==:#{session_windows},1}' 'set status off'"

# Status update interval
set-option -g status-interval 2

set -g status-justify right
set -g status-bg default
set -g status-fg default
set -g status-interval 5

# Window list
setw -g window-status-format '#[fg=black,bold]#I:#W'
setw -g window-status-current-format '#[fg=white]#I:#W'

# Left
set -g status-left '#[fg=black,bold]#(whoami)@#H #[fg=blue]>>#[fg=white,bold] #T'
set -g status-left-length 60

# Right
set -g status-right ''

# Pane border
set-option -g pane-border-style bg=default
set-option -g pane-border-style fg=brightblack
set-option -g pane-active-border-style bg=default
set-option -g pane-active-border-style fg=white

# Pane number indicator
set-option -g display-panes-colour brightblack
set-option -g display-panes-active-colour brightwhite

# Clock mode
set-option -g clock-mode-colour white
set-option -g clock-mode-style 24

# Message
set-option -g message-style bg=default
set-option -g message-style fg=default

# Activity
set-window-option -g monitor-activity on
set-option -g visual-activity on

# Mouse stuff
setw -g mouse on

# Log output to a text file on demand
bind P pipe-pane -o "cat >>~/#W.log" \; display "Toggled logging to ~/#W.log"

# move between panes
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
